//
//  BAHomeBottomView.swift
//  BAweibo
//
//  Created by baggio on 2017/8/19.
//  Copyright © 2017年 baggio. All rights reserved.
//

import UIKit

class BAHomeBottomView: UIView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setUpUI() {
        //测试
        backgroundColor = randomColor()
        backgroundColor = UIColor.white
        
        addSubview(retweetBtn)
        addSubview(commentBtn)
        addSubview(unlikeBtn)
        
        let line1 = addLines()
        let line2 = addLines()
        
//        addSubview(lineA)
//        addSubview(lineB)
        
        retweetBtn.snp.makeConstraints { (m) in
            m.left.top.bottom.equalTo(self)
            m.width.equalTo(commentBtn) //第一个按钮的宽度==第二个按钮，第二个按钮的宽度==第三个按钮，三等分
        }
        
        commentBtn.snp.makeConstraints { (m) in
            m.left.equalTo(retweetBtn.snp.right)
            m.top.bottom.equalTo(self)
            m.width.equalTo(unlikeBtn)
        }
        
        unlikeBtn.snp.makeConstraints { (m) in
            m.left.equalTo(commentBtn.snp.right)
            m.top.bottom.right.equalTo(self)
        }
        
        line1.snp.makeConstraints { (m) in
//            m.left.equalTo(retweetBtn.snp.right)
//            m.top.bottom.equalTo(retweetBtn)
            //图和文混着约束，一般用 center
            m.centerX.equalTo(retweetBtn.snp.right)
            m.centerY.equalTo(self)
        }
        
        line2.snp.makeConstraints { (m) in
            m.centerX.equalTo(commentBtn.snp.right)
            m.centerY.equalTo(self)
        }
        
//        lineA.snp.makeConstraints { (m) in
//            m.centerX.equalTo(retweetBtn.snp.right)
//            m.centerY.equalTo(self)
//            m.width.equalTo(1)
//            m.height.equalTo(retweetBtn).multipliedBy(0.4)
//        }
//        
//        lineB.snp.makeConstraints { (m) in
//            m.centerX.equalTo(commentBtn.snp.right)
//            m.centerY.equalTo(self)
//            m.width.equalTo(1)
//            m.height.equalTo(retweetBtn).multipliedBy(0.4)
//        }
 
    }
    
    
    //3个按妞
    private lazy var retweetBtn: UIButton = UIButton(title: "转发", titleColor: UIColor.darkGray, titleColorHighlight: BA_COLOR_APP_THEME, titleLabelFont: 14, imgName: "timeline_icon_retweet", backgroundImgName: "timeline_card_bottom_background", target: nil, action: nil)
    
    private lazy var commentBtn: UIButton = UIButton(title: "评论", titleColor: UIColor.darkGray, titleColorHighlight: BA_COLOR_APP_THEME, titleLabelFont: 14, imgName: "timeline_icon_comment", backgroundImgName: "timeline_card_bottom_background", target: nil, action: nil)
    
    private lazy var unlikeBtn: UIButton = UIButton(title: "点赞", titleColor: UIColor.darkGray, titleColorHighlight: BA_COLOR_APP_THEME, titleLabelFont: 14, imgName: "timeline_icon_unlike", backgroundImgName: "timeline_card_bottom_background", target: nil, action: nil)
    
    //添加竖线，用 UIImageView
    private func addLines() -> UIImageView {
        let lineImageView = UIImageView(imgName: "timeline_card_bottom_line")
        addSubview(lineImageView)
        return lineImageView
    }
    
    //竖线也可以不用 UIImageView ，直接用宽度为1高度为 button*0.4 的 UIView
//    private lazy var lineA: UIView = {
//        let v = UIView()
//        v.backgroundColor = UIColor.gray
//        return v
//    }()
//    
//    private lazy var lineB: UIView = {
//        let v = UIView()
//        v.backgroundColor = UIColor.gray
//        return v
//    }()
    
}
